﻿@using Coralcode.Adapter.StatVisit.Entity.Domains
@using Coralcode.Adapter.StatVisit.Entity.Enums
@using CoralNode.MvcClient.Helper
@{
    ViewBag.Title = "流量分析";
    ViewBag.PageModule = "flow";
    ViewBag.CurrentPageUrl = "/m/statistic/flow?";
}
@Html.IncludePage("CoralAdmin/statistic", "_Left")
<!--content-->
<div id="pbody">
    <div class="extra">
        @Html.IncludePage("CoralAdmin/statistic", "DateSelection")
        <div class="main-box mt_2 mb_2">
            <div class="tab-visit clearfix">
                <a class="current" href="/m/statistic/flow?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">
                    访问趋势</a>
                <a href="/m/statistic/flowreport?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">
                    统计报表</a>
                <a href="/m/statistic/flowlog?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">
                    访问明细</a>
            </div>
            <div class="clearfix h_48">
                <div class="visit-trend">
                    <div class="t clearfix">
                        <div class="f_l">
                            <select>
                                <option>选择指标</option>
                                <option>浏览次数(PV)</option>
                                <option>独立访客 (UV)</option>
                                <option>IP</option>
                                <option>新独立访客</option>
                                <option>访问次数</option>
                                <option>人均浏览页数</option>
                                <option>平均访问深度</option>
                                <option>平均访问时长</option>
                                <option>跳出率</option>
                            </select>
                        </div>
                        <div class="filter_btn  filter_btn-2 f_r">
                            @if (ViewBag.IsLongDuration) {
                                <a class="w_3-5 @if (ViewBag.ReportDateType == StatReportDateTypeEnum.Day) {@String.Format("current")}" href="/m/statistic/flow?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&reportDateType=@StatReportDateTypeEnum.Day">
                                    日</a>
                                <a class="last w_3-5 @if (ViewBag.ReportDateType == StatReportDateTypeEnum.Week) {@String.Format("current")}" href="/m/statistic/flow?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&reportDateType=@StatReportDateTypeEnum.Week">
                                    周</a>
                            } else {
                                <a class="w_3-5 @if (ViewBag.ReportDateType == StatReportDateTypeEnum.Hour) {@String.Format("current")}" href="/m/statistic/flow?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&reportDateType=@StatReportDateTypeEnum.Hour">
                                    时</a>
                                <a class="last w_3-5 @if (ViewBag.ReportDateType == StatReportDateTypeEnum.Day) {@String.Format("current")}" href="/m/statistic/flow?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&reportDateType=@StatReportDateTypeEnum.Day">
                                    日</a>
                            }
                        </div>
                    </div>
                    <div class="cnt_main mt_2" id="chartContainer"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/Themes/CoralAdmin/_misc/scripts/Highcharts/js/highcharts.src.js"></script>
<script type="text/javascript">
    $(function () {
        $('#chartContainer').highcharts({
            title: {
                text: ''
            },
            credits: {
                enabled:false
            },
            xAxis: {
                categories: [
			          @{ var categories = new List<string>(); }
                      @if (ViewBag.ReportDateType == StatReportDateTypeEnum.Hour) {
                          foreach (StatReportDomain report in ViewBag.Reports) {
                              categories.Add(string.Format("'{0}'", report.ReportDate.ToString("MM-dd HH:mm")));
                          }
                      } else if (ViewBag.ReportDateType == StatReportDateTypeEnum.Day) {
                          foreach (StatReportDomain report in ViewBag.Reports) {
                              categories.Add(string.Format("'{0}'", report.ReportDate.ToString("MM-dd")));
                          }
                      } else if (ViewBag.ReportDateType == StatReportDateTypeEnum.Week) {
                          foreach (StatReportDomain report in ViewBag.Reports) {
                              var reportEndTime = report.ReportDate.AddDays(1);
                              while (reportEndTime.DayOfWeek != DayOfWeek.Monday) {
                                  reportEndTime = reportEndTime.AddDays(1);
                              }
                              reportEndTime = reportEndTime.AddDays(-1);
                              reportEndTime = reportEndTime < DateTime.Now ? reportEndTime : DateTime.Now;
                              if (reportEndTime.Equals(report.ReportDate)) {
                                  categories.Add(string.Format("'{0}'", report.ReportDate.ToString("MM-dd")));
                              } else {
                                  categories.Add(string.Format("'{0}至{1}'", report.ReportDate.ToString("MM-dd"), reportEndTime.ToString("MM-dd")));
                              }
                          }
                      }
			          @Html.Raw(string.Join(",", categories))
			      ],
			      @{
                      var interval = ViewBag.Reports.Count > 24 ? ViewBag.Reports.Count / 24 + 1 : 1;
		          }
			      tickInterval: @interval
			      },
		      yAxis: {
		          title:{text:""}
		      },
		      tooltip: {
				  
		      },
		      legend: {
		          borderWidth: 0
		      },
		      series: [
			      @{
                      var pvstr = new List<string>();
                      var uvstr = new List<string>();
                      var ipstr = new List<string>();
			      }
			      @foreach (StatReportDomain report in ViewBag.Reports) {
             pvstr.Add(report.PageView.ToString());
             uvstr.Add(report.UniqueVisitor.ToString());
             ipstr.Add(report.IpCount.ToString());
         }
			      {
			          name: '浏览次数（PV）',
			          data: [@string.Join(",", pvstr)]
			      }, {
			          name: '独立访客（UV）',
			          data: [@string.Join(",", uvstr)]
			  }, {
			      name: 'IP',
			      data: [@string.Join(",", ipstr)]
			  }
			  ]
		  });
	    });
</script>
